require "stockpriceprovider/stockpriceprovider.rb"

class IndexController < ApplicationController

  def index
    @activeGroups = Group.listOpen
    @closedGroups = Group.listClosed
  end

  def currentValue
    @group = Group.find(params[:id])
    @currVal = StockPriceProviderFactory.getStockPriceProvider.stockValueFor(@group.share.name)
    unless @currVal.nil? or @currVal.getPrice().to_f < 0
      @income = @group.quantity * @currVal.getPrice().to_f
      @brokerage = @group.account.calculateBrokerage(@income)
      @total = @group.balance + (@currVal.getPrice().to_f * @group.quantity) - @brokerage
    end
    render :layout => false
  end

end
